home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / ifupdown < prev    next >
Encoding:
Text File  |  2013-01-10  |  2.5 KB  |  116 lines

  1. #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides:          ifupdown
  4. # Required-Start:    ifupdown-clean
  5. # Required-Stop:     $local_fs
  6. # Default-Start:     S
  7. # Default-Stop:
  8. # Short-Description: Prepare the system for taking up interfaces.
  9. ### END INIT INFO
  10.  
  11. [ -x /sbin/ifup ] || exit 0
  12. [ -x /sbin/ifdown ] || exit 0
  13.  
  14. . /lib/lsb/init-functions
  15.  
  16. MYNAME="${0##*/}"
  17. report() { echo "${MYNAME}: $*" ; }
  18. report_err() { log_failure_msg "$*" ; }
  19. RUN_DIR=/etc/network/run
  20. [ -r /etc/default/ifupdown ] && . /etc/default/ifupdown
  21.  
  22. # Note: The state file location is hardcoded in ifup|ifdown
  23. IFSTATE=/etc/network/run/ifstate
  24.  
  25. myreadlink () {
  26.   dest="${1%/}"
  27.   extras=""
  28.  
  29.   while [ "$dest" != "" ]; do
  30.     if [ -d "$dest" ]; then
  31.       cd "$dest"
  32.       dest=$(/bin/pwd)
  33.       break
  34.     fi
  35.  
  36.     if [ -L "$dest" ]; then
  37.       d2=$(readlink "$dest")
  38.       if [ "${d2#/}" = "$d2" ]; then
  39.         dest="${dest%/*}/$d2"
  40.       else
  41.         dest="$d2"
  42.       fi
  43.     fi
  44.  
  45.     while [ ! -e "$dest" ]; do
  46.       extras="${dest##*/}/$extras"
  47.       if [ "${extras%%/*}" = ".." ]; then return 1; fi
  48.       destx="${dest%/*}"
  49.       if [ "$destx" = "$dest" ]; then destx=""; fi
  50.       dest="$destx"
  51.     done
  52.   done
  53.   dest="$dest/$extras"
  54.   echo "${dest%/}"
  55. }
  56.  
  57. case "$1" in
  58.   start|restart)
  59.     if [ "$2" ]; then
  60.       report_err "Arguments to '$1' command not accepted"
  61.       exit 3
  62.     fi
  63.     log_begin_msg "Setting up networking..."
  64.  
  65.     # if /etc/network/run is a symlink to a directory that doesn't exist,
  66.     # create it.
  67.  
  68.     if [ -L "$RUN_DIR" ] && [ ! -d "$RUN_DIR" ] ; then
  69.       runmkdir="$(myreadlink "$RUN_DIR")"
  70.       if [ ! "$runmkdir" ] ; then
  71.         report_err "Cannot create target of /etc/network/run"
  72.         log_end_msg 1
  73.         exit 1
  74.       fi
  75.       if ! mkdir -p "$runmkdir"; then
  76.         report_err "Failure creating directory $runmkdir"
  77.         log_end_msg 1
  78.         exit 1
  79.       fi
  80.     fi
  81.  
  82.     # Create the state file
  83.     # Doing this also signals that ifupdown is available for use
  84.     if [ ! -r "$IFSTATE" ]; then
  85.       if ! : > "$IFSTATE" ; then
  86.         report_err "Failure initializing $IFSTATE"
  87.         log_end_msg 1
  88.         exit 1
  89.       fi 
  90.     fi
  91.  
  92.     log_end_msg 0
  93.     exit 0
  94.     ;;
  95.  
  96.   stop)
  97.     if [ "$2" ]; then
  98.       report_err "Arguments to '$1' command not accepted"
  99.       exit 3
  100.     fi
  101.     if [ -x /etc/init.d/ifupdown-clean ]; then
  102.       /etc/init.d/ifupdown-clean start
  103.     fi
  104.     ;;
  105.  
  106.   force-reload)
  107.     ;;
  108.  
  109.   *)
  110.     echo "Usage: $0 {start|stop|restart|force-reload}" >&2
  111.     exit 3
  112.     ;;
  113. esac
  114.  
  115. exit 0
  116.